package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: OrderController
 * @Author: YuanDing
 * @Date: 2024/2/8 11:30
 * @Description:
 */

@Api("订单管理")
@RestController
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrderService service;

    @ApiOperation("订单条件搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch( OrdersPageQueryDTO ordersPageQueryDTO) {
        Result result = service.conditionSearch(ordersPageQueryDTO);
        return result;
    }

    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result orderDetail(@PathVariable Long id) {
        Result result = service.orderDetail(id);
        return result;
    }

    /**
     * 各订单状态统计
     * @return
     */
    @ApiOperation("各订单状态统计")
    @GetMapping("/statistics")
    public Result statistics() {
        Result result = service.statistics();
        return result;
    }

    /**
     * 接单
     * @param orders
     * @return
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody Orders orders) {
        service.confirm(orders.getId());
        return Result.success();
    }
    /**
     * 派单
     * @param id
     * @return
     */
    @ApiOperation("派单")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id) {
        service.delivery(id);
        return Result.success();
    }
    /**
     * 拒单
     * @param ordersRejectionDTO
     * @return
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        service.rejection(ordersRejectionDTO);
        return Result.success();
    }
    /**
     * 取消订单
     * @param ordersCancelDTO
     * @return
     */
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        service.cancel(ordersCancelDTO);
        return Result.success();
    }
    /**
     * 完成订单
     * @param id
     * @return
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id) {
        service.complete(id);
        return Result.success();
    }




}
